{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "abd36a8b-9e26-4315-9f5c-dfb2559f808b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2x3的数组arr1: \n",
      " [[10 20 30]\n",
      " [40 50 60]]\n",
      "2x3的数组arr2: \n",
      " [[1 2 2]\n",
      " [2 2 3]]\n",
      "arr1与arr2的加法运算: \n",
      " [[11 22 32]\n",
      " [42 52 63]]\n",
      "arr1与arr2的减法运算: \n",
      " [[ 9 18 28]\n",
      " [38 48 57]]\n",
      "arr1与arr2的乘法运算: \n",
      " [[ 10  40  60]\n",
      " [ 80 100 180]]\n",
      "arr1与arr2的除法运算: \n",
      " [[10. 10. 15.]\n",
      " [20. 25. 20.]]\n",
      "arr1与arr2的幂运算: \n",
      " [[    10    400    900]\n",
      " [  1600   2500 216000]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "arr1 = np.array([[10,20,30],[40,50,60]])\n",
    "print('2x3的数组arr1: \\n',arr1)\n",
    "arr2 = np.array([[1,2,2],[2,2,3]])\n",
    "print('2x3的数组arr2: \\n',arr2)\n",
    "print('arr1与arr2的加法运算: \\n',arr1+arr2)\n",
    "print('arr1与arr2的减法运算: \\n',arr1-arr2)\n",
    "print('arr1与arr2的乘法运算: \\n',arr1*arr2)\n",
    "print('arr1与arr2的除法运算: \\n',arr1/arr2)\n",
    "print('arr1与arr2的幂运算: \\n',arr1**arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "131fc2f7-757a-47e3-ad3b-9181f84f2728",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "arr1与arr2相加: \n",
      " [[11 22 33]\n",
      " [41 52 63]]\n",
      "arr1与arr3相加: \n",
      " [[11 21 31]\n",
      " [42 52 62]]\n",
      "arr1与arr4相加: \n",
      " [[15 25 35]\n",
      " [45 55 65]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "arr1 = np.array([[10,20,30],[40,50,60]])\n",
    "arr2 = np.array([1,2,3])\n",
    "print('arr1与arr2相加: \\n',arr1+arr2)\n",
    "arr3 = np.array([[1],[2]])\n",
    "print('arr1与arr3相加: \\n',arr1+arr3)\n",
    "arr4 = np.array(5)\n",
    "print('arr1与arr4相加: \\n',arr1+arr4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6c23110e-3a87-4f43-91a4-12bda9b77b7b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3x4的原数组: \n",
      " [[62 61 55  6]\n",
      " [76 20 96  9]\n",
      " [79  7 43 30]]\n",
      "转置后4x3的数组: \n",
      " [[62 76 79]\n",
      " [61 20  7]\n",
      " [55 96 43]\n",
      " [ 6  9 30]]\n",
      "变形后2x6的数组: \n",
      " [[62 61 55  6 76 20]\n",
      " [96  9 79  7 43 30]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "arr = np.random.randint(1,100,size=(3,4))\n",
    "print('3x4的原数组: \\n',arr)\n",
    "print('转置后4x3的数组: \\n',arr.T)\n",
    "print('变形后2x6的数组: \\n',arr.reshape(2,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "de78c4aa-0b3e-490a-b51e-50cd7133c702",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "随机生成的二维整数数组arr1: \n",
      " [[4 3 8]\n",
      " [7 6 4]\n",
      " [8 3 5]]\n",
      "随机生成的一维整数数组arr2: \n",
      " [6 8 8]\n",
      "随机生成的二维小数数组arr3: \n",
      " [[7.28108099 9.42693799 2.53628487]\n",
      " [7.85023641 1.78950868 3.22448262]\n",
      " [9.75807885 8.93105305 5.34554036]]\n",
      "arr1和arr2相加: \n",
      " [[10 11 16]\n",
      " [13 14 12]\n",
      " [14 11 13]]\n",
      "arr1和arr3相乘: \n",
      " [[29.12432396 28.28081396 20.290279  ]\n",
      " [54.95165487 10.73705211 12.89793046]\n",
      " [78.06463078 26.79315914 26.72770178]]\n",
      "以arr1为底数,arr2为指数的幂: \n",
      " [[    4096     6561 16777216]\n",
      " [  117649  1679616    65536]\n",
      " [  262144     6561   390625]]\n",
      "arr1的倒数: \n",
      " [[0.25       0.33333333 0.125     ]\n",
      " [0.14285714 0.16666667 0.25      ]\n",
      " [0.125      0.33333333 0.2       ]]\n",
      "以arr3四舍五入,小数点后保留一位: \n",
      " [[7.3 9.4 2.5]\n",
      " [7.9 1.8 3.2]\n",
      " [9.8 8.9 5.3]]\n",
      "arr1的余弦值: \n",
      " [[0.99756405 0.99862953 0.99026807]\n",
      " [0.99254615 0.9945219  0.99756405]\n",
      " [0.99026807 0.99862953 0.9961947 ]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "arr1 = np.random.randint(1,10,size=(3,3))\n",
    "print('随机生成的二维整数数组arr1: \\n',arr1)\n",
    "arr2 = np.random.randint(1,10,size=3)\n",
    "print('随机生成的一维整数数组arr2: \\n',arr2)\n",
    "arr3 = np.random.rand(3,3)*10\n",
    "print('随机生成的二维小数数组arr3: \\n',arr3)\n",
    "print('arr1和arr2相加: \\n',np.add(arr1,arr2))\n",
    "print('arr1和arr3相乘: \\n',np.multiply(arr1,arr3))\n",
    "print('以arr1为底数,arr2为指数的幂: \\n',np.power(arr1,arr2,dtype='int64'))\n",
    "print('arr1的倒数: \\n',np.reciprocal(arr1,dtype='float'))\n",
    "print('以arr3四舍五入,小数点后保留一位: \\n',np.around(arr3,decimals=1))\n",
    "print('arr1的余弦值: \\n',np.cos(arr1*np.pi/180))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b54396fd-49cf-4376-b6b1-244c1dcee337",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
